import { find } from 'lodash';
export const getTableColumns = ({ permsList }: any) => [
	{
		title: "角色编号",
		dataIndex: "id",
		width: 140,
		ellipsis: true
	},
	{
		title: "角色名称",
		dataIndex: "name",
		width: 140,
		ellipsis: true
	},
	{
		title: "权限字符",
		dataIndex: "code",
		width: 140,
		ellipsis: true
	},
	{
		title: "数据权限",
		dataIndex: "dataScope",
		width: 140,
		ellipsis: true,
		render: (_: any, record: any) => {
			const result = find(permsList?.data || [], (item: any) => item.value === record.dataScope)
			return (
				<span>
					{result?.label}
				</span>
			)
		}
	},
	{
		title: "角色状态",
		dataIndex: "status",
		width: 100,
		ellipsis: true,
		render: (_: any, record: any) => {
			return (
				<span style={{}}>
					{COMMON_STATUS.find(item => `${item.value}` === `${record.status}`)?.label}
				</span>
			)
		}
	},
	{
		title: "创建时间",
		dataIndex: "createTime",
		width: 100,
		ellipsis: true,
	},
];

export const COMMON_STATUS = [
	{ label: '停用', value: 0 },
	{ label: '正常', value: 1 }
]

export const getSearchColumns = ({permsList}: any) => [
	{
		type: "input",
		placeholder: "角色名称",
		name: "name"
	},
	{
		type: "select",
		placeholder: "数据权限",
		name: "dataScope",
		options: permsList?.data || [],
	},
	{
		type: "select",
		placeholder: "角色状态",
		name: "status",
		options: COMMON_STATUS
	},
]


export const getCreateColumns = (permsList: any) => [
	{
		type: "input",
		placeholder: "角色名称",
		label: "角色名称",
		name: "name",
		rules: [{ required: true, message: '这是必填项' }]
	},
	{
		type: "input",
		placeholder: "权限字符",
		label: "权限字符",
		name: "code",
		rules: [{ required: true, message: '这是必填项' }]
	},
	{
		type: "radioGroup",
		placeholder: "状态",
		label: "状态",
		name: "status",
		options: COMMON_STATUS,
		rules: [{ required: true, message: '这是必填项' }]
	},
	{
		type: "select",
		placeholder: "数据权限",
		label: "数据权限",
		name: "dataScope",
		request: () => permsList?.data || [],
		rules: [{ required: true, message: '这是必填项' }]
	},
	{
		type: "input",
		placeholder: "备注",
		label: "备注",
		name: "remark",
	},
]